﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;

namespace WorkFlowData
{
    /// <summary>
    /// 本类主要用于提供一些常用的转换工具
    /// </summary>
    class Tools
    {
        /// <summary>
        /// 数据序列化函数
        /// </summary>
        /// <param name="sb"></param>
        /// <returns></returns>
        public static  string ObjectToJson(object sb)
        {
            if (sb == null)
            {
                return string.Empty;
            }
            else
            {
                try
                { 
                    var serializer = new JavaScriptSerializer();
                    string json = serializer.Serialize(sb);
                    return json;
                }
                catch (Exception ex)
                {
                    return  ex.ToString();
                }
            }
        }
    }
}
